﻿<UserControl x:Class="Microsoft.Research.ScientificWorkflow.UIDesigner.Monitor.InputOutputView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Converters="clr-namespace:Microsoft.Research.ScientificWorkflow.UIDesigner.Monitor"
    Height="Auto" Width="Auto">
    <UserControl.Resources>
        <Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
            <Setter Property="AutomationProperties.Name" Value="{Binding Path=Name}"/>
        </Style>
        
        <Converters:ComplexDataTemplateSelector x:Key="complexDataTemplateSelector"></Converters:ComplexDataTemplateSelector>
        <Style x:Key="TreeViewItemFocusVisual">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
        <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Width" Value="16"/>
            <Setter Property="Height" Value="16"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Width="16" Height="16" Background="Transparent" Padding="5,5,5,5">
                            <Path Fill="Transparent" Stroke="#FF989898" x:Name="ExpandPath" Data="{StaticResource TreeArrow}">
                                <Path.RenderTransform>
                                    <RotateTransform Angle="135" CenterX="3" CenterY="3"/>
                                </Path.RenderTransform>
                            </Path>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1BBBFA"/>
                                <Setter Property="Fill" TargetName="ExpandPath" Value="Transparent"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="RenderTransform" TargetName="ExpandPath">
                                    <Setter.Value>
                                        <RotateTransform Angle="180" CenterX="3" CenterY="3"/>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
                                <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="TreeViewItemStyle1" TargetType="{x:Type TreeViewItem}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="Padding" Value="1,0,0,0"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid Background="Green">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="19" Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
                            <Border x:Name="Bd" SnapsToDevicePixels="true" Grid.Column="1" Background="Transparent" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition MinWidth="26"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter HorizontalAlignment="Stretch" x:Name="PART_Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" Grid.ColumnSpan="1" Grid.Column="1"/>
                                    <Image Grid.ColumnSpan="1" Source="/Microsoft.Research.ScientificWorkflow.TridentUtilities;component/Images/ScientificWorkflow/DataStoreICon.png" Width="22" Height="22" HorizontalAlignment="Left" VerticalAlignment="Center" Stretch="None"/>
                                </Grid>
                            </Border>
                            <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="false">
                                <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                            </Trigger>
                            <Trigger Property="HasItems" Value="false">
                                <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Foreground" Value="#FF000000"/>

                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="IsSelectionActive" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!--Style for all the TextBlock-->
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Text }"/>
            <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
            <Setter Property="MaxHeight" Value="15" />
            <!--<Setter Property="AutomationProperties.AutomationId" Value="{Binding RelativeSource={RelativeSource Self}, Path=AutomationProperties.AutomationId }"/>-->
            <!--Value= "{Binding AutomationProperties.AutomationId,RelativeSource={RelativeSource FindAncestor, AncestorType='GridViewColumn'}}" />-->
        </Style>

        <!--Data template for the input output params-->
        <DataTemplate x:Key="ActivityPropertyModel_template">
            <Grid Margin="0,0,0,0" HorizontalAlignment="Stretch" Width="Auto"  >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" MinHeight="50"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <DockPanel Margin="-1,0,0,0" Grid.Row="0">
                    <ListView HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" IsSynchronizedWithCurrentItem="True" BorderBrush="#FFCECECE"  Margin="0,0,0,0" ItemsSource="{Binding Path=InputProperties}">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn  Width="150" DisplayMemberBinding="{Binding Path=Name}" >
                                    <GridViewColumn.Header>
                                        <TextBlock Text="Input Parameter" FontWeight="Bold"></TextBlock>
                                    </GridViewColumn.Header>

                                </GridViewColumn>
                                <GridViewColumn Width="200"  DisplayMemberBinding="{Binding Path=Value}"  >
                                    <GridViewColumn.Header>
                                        <TextBlock Text="Value" FontWeight="Bold"></TextBlock>
                                    </GridViewColumn.Header>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                </DockPanel>
                <DockPanel Grid.Row="1" Margin="-1,0,0,0">
                    <ListView HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" IsSynchronizedWithCurrentItem="True" BorderBrush="#FFCECECE" Margin="0,0,0,0"  ItemsSource="{Binding Path=OutputProperties}">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn  Width="150" DisplayMemberBinding="{Binding Path=Name}" >
                                    <GridViewColumn.Header>
                                        <TextBlock Text="Output Parameter" FontWeight="Bold"></TextBlock>
                                    </GridViewColumn.Header>
                                </GridViewColumn>
                                <GridViewColumn Width="200"  DisplayMemberBinding="{Binding Path=Value}" >
                                    <GridViewColumn.Header>
                                        <TextBlock Text="Value" FontWeight="Bold"></TextBlock>
                                    </GridViewColumn.Header>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                </DockPanel>
            </Grid>
        </DataTemplate>

        <!--Data template for the activity tree-->
        <HierarchicalDataTemplate x:Key="ActivityViewModel_template" ItemsSource="{Binding Path = DisplayItems}" ItemTemplateSelector="{StaticResource complexDataTemplateSelector}">
            <!--<HierarchicalDataTemplate.ItemsSource>
                <MultiBinding Converter="{StaticResource complexGroupConverter}">
                    <Binding Path="Properties" NotifyOnSourceUpdated="True"/>
                    <Binding Path="Iterations" NotifyOnSourceUpdated="True"/>
                </MultiBinding>
            </HierarchicalDataTemplate.ItemsSource>-->
            <DockPanel Margin="0,2,0,2">
                <Image Source="/Microsoft.Research.ScientificWorkflow.TridentUtilities;component/Images/ScientificWorkflow/DataStoreICon.png" Margin="0,0,5,0"/>
                <TextBlock Text="{Binding Path=Label}" />
            </DockPanel>
        </HierarchicalDataTemplate>

        <!--Data template for the iterations-->
        <HierarchicalDataTemplate x:Key="InputOutputIterationViewModel_template" ItemsSource="{Binding Path=Activities}" ItemTemplate="{StaticResource ActivityViewModel_template}">
            <DockPanel Margin="0,2,0,2">
                <Image Source="/Microsoft.Research.ScientificWorkflow.TridentUtilities;component/Images/ScientificWorkflow/DataStoreICon.png" Margin="0,0,5,0"/>
                <TextBlock Text="{Binding Path=Name}" />
            </DockPanel>
        </HierarchicalDataTemplate>

    </UserControl.Resources>
    <Grid>
        <TreeView ItemsSource="{Binding Path=ActivityCollection}" ItemTemplate="{StaticResource ActivityViewModel_template}"  Width="Auto" Height="Auto" BorderThickness="1">

        </TreeView>
    </Grid>
</UserControl>
